package com.eight.travel.controller;

import com.eight.travel.pojo.Foodcomment;
import com.eight.travel.service.FoodService;
import com.eight.travel.utils.BaseResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/foot")
@CrossOrigin
@Api(value = "前端用户功能")
public class FoodController {
    @Autowired
    FoodService foodService;
    @ApiOperation(value = "查询所有food，以及该food所对应的所有餐厅")
    @GetMapping("/findAll")
    public BaseResp findAllFood(){
        BaseResp allFood = foodService.findAllFood();
        return allFood;
    }
    @ApiOperation(value = "根据id查询餐厅",notes = "传入餐厅id")
    @GetMapping("findrest/{fid}")
    public BaseResp findrestByFid(int fid){
        return foodService.findrestByFid(fid);
    }

    @ApiOperation(value = "根据热度查询food",notes = "传入当前页和每页行数")
    @GetMapping("/findhot/{page}/{size}")
    public BaseResp findByHot(@PathVariable int page,@PathVariable int size){
        return foodService.findByHot(page, size);
    }
    @ApiOperation(value = "根据价格查询food",notes = "传入当前页和每页行数")
    @GetMapping("/findprice/{page}/{size}")
    public BaseResp findByPrice(@PathVariable int page,@PathVariable int size){
        return foodService.findByPrice(page, size);
    }
    @ApiOperation(value = "模糊查询",notes = "传入食物名字")
    @GetMapping("/findname/{foodname}")
    public BaseResp findByName(String foodname){
        return foodService.findByName(foodname);
    }
    @ApiOperation(value = "分页查询",notes = "传入当前页和每页行数")
    @GetMapping("/findPage")
    public BaseResp findByPage( int page, int size){
        return foodService.findByPage(page,size);
    }
    @ApiOperation(value = "增加food热度",notes = "传入食物id")
    @GetMapping("/addHot/{fid}")
    public BaseResp addHot(int fid){
        return foodService.addHot(fid);
    }
    @ApiOperation(value = "减少food热度",notes = "传入食物id")
    @GetMapping("/reduceHot/{fid}")
    public BaseResp reduceHot(int fid){
        return foodService.addHot(fid);
    }
    @ApiOperation(value = "增加评论",notes = "foodcomment")
    @PostMapping("/addcomment")
    public BaseResp addcomment(@RequestBody Foodcomment foodcomment){
        return foodService.addcomment(foodcomment);
    }
    @ApiOperation(value = "查询所有评论")
    @GetMapping("/findAllcomm")
    public BaseResp findAllcomm(){
        BaseResp findcomment = foodService.findcomment();
        return findcomment;
    }


}
